//
//  HomeBalanceCell.swift
//  d11
//
//  Created by peale on 2018/8/7.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit
typealias BonusClickBlock2 = (_ tag: Int) -> Void
class HomeBalanceCell: UITableViewCell {
    var bonusClickBlock2: BonusClickBlock2?
    func callChangeBlock(_ block: @escaping BonusClickBlock2) {
        
        bonusClickBlock2 = block
    }
    var backwaterBtn : UIButton?
    var backwaterImgView: UIImageView?
    var backwaterLabel: UILabel?
    var backwaterMoneyLabel: UILabel?
    
    var dividendBtn : UIButton?
    var dividendImgView: UIImageView?
    var dividendLabel: UILabel?
    var dividendMoneyLabel: UILabel?
    var lineView :UIView?
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func setUpUI() -> Void {
        self.backgroundColor  = UIColor.white
        self.selectionStyle = UITableViewCell.SelectionStyle.none
        self.backwaterBtn = UIButton.init(type: .custom)
        self.backwaterBtn?.addTarget(self, action: #selector(self.actionToClick(_:)), for: .touchUpInside)
        self.backwaterBtn?.tag = 1001
        self.contentView.addSubview(self.backwaterBtn!)
        self.backwaterBtn?.snp.makeConstraints{(make) in
            make.width.equalTo((kScreenWidth)/2)
            make.height.equalToSuperview()
            make.top.equalToSuperview()
            make.left.equalToSuperview().offset(10)
        }
        
        self.backwaterImgView = UIImageView.init(image: imageNamed("img_default_60"))
        self.backwaterBtn?.addSubview(self.backwaterImgView!)
        self.backwaterImgView?.snp.makeConstraints{(make) in
            make.width.equalTo(65)
            make.height.equalTo(65)
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-10)
        }
        
        self.backwaterLabel =  UILabel.init()
        self.backwaterLabel?.font = UIFont.systemFont(ofSize: 14)
        backwaterLabel?.textColor = UIColor.black
        backwaterLabel?.textAlignment = .left
        backwaterLabel?.text = "返水到账"
        self.backwaterBtn?.addSubview(self.backwaterLabel!)
        self.backwaterLabel?.snp.makeConstraints{(make) in
            make.left.equalToSuperview().offset(10)
            make.height.equalTo(20)
            make.centerY.equalToSuperview().offset(-5)
            make.right.equalTo((self.backwaterImgView?.snp.left)!).offset(-5)
        }
        
        self.backwaterMoneyLabel =  UILabel.init()
        self.backwaterMoneyLabel?.font = UIFont.systemFont(ofSize: 14)
        backwaterMoneyLabel?.textColor = HexRGBAlpha(0xffc569,1)
        backwaterMoneyLabel?.textAlignment = .left
        backwaterMoneyLabel?.text = "-"
        self.backwaterBtn?.addSubview(self.backwaterMoneyLabel!)
        self.backwaterMoneyLabel?.snp.makeConstraints{(make) in
            make.left.equalToSuperview().offset(10)
            make.height.equalTo(20)
            make.top.equalTo((backwaterLabel?.snp.bottom)!)
            make.right.equalTo((self.backwaterImgView?.snp.left)!).offset(-5)
        }
        
        
        
        //65 icon_home_fs icon_home_hl
        
        self.lineView = UIView.init()
        self.lineView?.backgroundColor = HexRGBAlpha(0xffc569,1)
        self.contentView.addSubview(self.lineView!)
        self.lineView?.snp.makeConstraints{(make) in
            make.width.equalTo(0.5)
            make.height.equalToSuperview().offset(-10)
            make.left.equalTo((self.backwaterBtn?.snp.right)!)
            make.top.equalToSuperview().offset(4)
        }
        
        self.dividendBtn = UIButton.init(type: .custom)
        self.dividendBtn?.addTarget(self, action: #selector(self.actionToClick(_:)), for: .touchUpInside)
        self.dividendBtn?.tag = 1002
        self.contentView.addSubview(self.dividendBtn!)
        self.dividendBtn?.snp.makeConstraints{(make) in
            make.width.equalTo((kScreenWidth)/2)
            make.height.equalToSuperview()
            make.right.equalToSuperview()
            //make.left.equalTo((self.lineView?.snp.right)!)
            make.top.equalToSuperview()
        }
        
        self.dividendImgView = UIImageView.init(image: imageNamed("img_default_60"))
        self.dividendBtn?.addSubview(self.dividendImgView!)
        self.dividendImgView?.snp.makeConstraints{(make) in
            make.width.equalTo(65)
            make.height.equalTo(65)
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-10)
        }
        
        self.dividendLabel =  UILabel.init()
        self.dividendLabel?.font = UIFont.systemFont(ofSize: 14)
        dividendLabel?.textColor = UIColor.black
        dividendLabel?.textAlignment = .left
        dividendLabel?.text = "最新红利"
        self.dividendBtn?.addSubview(self.dividendLabel!)
        self.dividendLabel?.snp.makeConstraints{(make) in
            make.left.equalToSuperview().offset(15)
            make.height.equalTo(20)
            make.centerY.equalToSuperview().offset(-5)
            make.right.equalTo((self.dividendImgView?.snp.left)!).offset(-5)
        }
        
        self.dividendMoneyLabel =  UILabel.init()
        self.dividendMoneyLabel?.font = UIFont.systemFont(ofSize: 14)
        dividendMoneyLabel?.textColor = HexRGBAlpha(0xffc569,1)
        dividendMoneyLabel?.textAlignment = .left
        dividendMoneyLabel?.text = "-"
        self.dividendBtn?.addSubview(self.dividendMoneyLabel!)
        self.dividendMoneyLabel?.snp.makeConstraints{(make) in
            make.left.equalToSuperview().offset(15)
            make.height.equalTo(20)
            make.top.equalTo((dividendLabel?.snp.bottom)!)
            make.right.equalTo((self.dividendImgView?.snp.left)!).offset(-5)
        }
    }
    
    @objc func actionToClick(_ sender:UIButton) -> Void {
        if bonusClickBlock2 != nil{
            bonusClickBlock2!(sender.tag)
        }
    }
    
    func setData(backwaterStr:String,dividendStr:String) -> Void {
        self.backwaterMoneyLabel?.text = backwaterStr
        self.dividendMoneyLabel?.text = dividendStr
        let rkImageURLs = GlobalInfo.gameInfoData?["fanshui_icon"] as? [String:String]
        let bonusImageURLs = GlobalInfo.gameInfoData?["hongli_icon"] as? [String:String]
        if let url = rkImageURLs?["imgNameIOS"] {
            backwaterImgView?.sd_setImage(with: URL(string: url), placeholderImage: imageNamed("img_default_60"), options: .refreshCached, completed: nil)
        }
        if let url = bonusImageURLs?["imgNameIOS"] {
            dividendImgView?.sd_setImage(with: URL(string: url), placeholderImage: imageNamed("img_default_60"), options: .refreshCached, completed: nil)
        }
    }

}
